package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.pojo.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    //http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}、

    /**
     * 品牌的分页查询
     * @param ps
     * @param pz
     * @return
     */
    @GetMapping("/{ps}/{pz}")
    public Result getPageTrademark(@PathVariable Long ps, @PathVariable Long pz){
        Page<BaseTrademark> page = new Page<>(ps,pz);
        Page<BaseTrademark> result = baseTrademarkService.page(page);
        return Result.ok(result);
    }

    //http://api.gmall.com/admin/product/baseTrademark/save

    /**
     * 新增一个品牌信息
     * @param baseTrademark
     * @return
     */
    @PostMapping("/save")
    public Result saveTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/update

    /**
     * 添加品牌信息
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public Result updateTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/remove/{id}

    /**
     * 删除指定的品牌
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result deleteTrademark(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    // http://api.gmall.com/admin/product/baseTrademark/get/{id}
    @GetMapping("/get/{id}")
    public Result getTrademarkById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //http://api.gmall.com/admin/product/baseTrademark/getTrademarkList

    /**
     * 获取品牌列表信息
     * @return
     */
    @GetMapping("/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }


}
